package edu.ucdavis.gwt.gis.client.extras;

import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Image;

public class MouseOverIcon extends Image {
	
	private ImageResource defaultResource = null;
	private ImageResource mouseOverResource = null;
	
	public MouseOverIcon() {
		super();
	}
	
	public MouseOverIcon(ImageResource defaultResource, ImageResource mouseOverResource) {
		super();
		setResources(defaultResource, mouseOverResource);
	}
	
	public void setResources(ImageResource defaultResource, ImageResource mouseOverResource) {
		this.defaultResource = defaultResource;
		this.mouseOverResource = mouseOverResource;
		init();
	}
	
	private void init() {
		setResource(defaultResource);
		addMouseOverHandler(new MouseOverHandler(){
			@Override
			public void onMouseOver(MouseOverEvent event) {
				setResource(mouseOverResource);
			}
		});
		addMouseOutHandler(new MouseOutHandler(){
			@Override
			public void onMouseOut(MouseOutEvent event) {
				setResource(defaultResource);
			}
		});
	}
	
}
